<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of FormValidator
 *
 * @author flocki
 */
namespace Taxx\KernelBundle\Model\FormValidator;

use Doctrine\ORM\EntityManager;

class FormValidator 
{
    public static function isEmpty($value)
    {
        if(trim($value)=="")
            return true;
        else
            return false;
    }
    
    public static function isSameValue($value_1, $value_2)
    {
        if($value_1==$value_2)
            return true;
        else
            return false;
    }
    
    public static function isSetInDatabase(EntityManager $em, $entity_name, array $entity_properties)
    {
        $result = $em->getRepository("TaxxKernelBundle:".$entity_name)->findBy($entity_properties);
        if(count($result)>0)
            return true;
        else
            return false;
    }
    
    public static function isValidEmail($email)
    {
        if (preg_match("/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/", $email)) 
           return true;
        else
            return false;
    }
   
}

?>
